package com.gxa.meiye.admin.controller.zy;

import com.gxa.meiye.admin.service.ICouponService;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.pojo.domain.Coupon;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-22  15:08
 */
@RestController
@Api(value="优惠卷",tags = "优惠卷接口")
@RequestMapping("/coupon")
public class CouponController {
    @Autowired
    private ICouponService iCouponService;
    //查看优惠卷
    @ApiOperation("查看优惠卷")
    @PostMapping("/select")
    public Map select(String phone){
        List<Coupon> list = iCouponService.list(phone);
        JsonResult jsonResult=new JsonResult();
        if (list!=null){
            jsonResult.setCode("1");
            jsonResult.setMsg("当前用户存在优惠卷");
            jsonResult.setData(list);
        }
        return jsonResult.getMap();
    }
    //兑换优惠卷
    @ApiOperation("兑换优惠卷")
    @PostMapping("/used")
    public Map used(String title,String phone){
        Integer update = iCouponService.update(title, phone);
        JsonResult jsonResult=new JsonResult();
        if (update!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("兑换成功");

        }
        return jsonResult.getMap();
    }
    //删除优惠卷
//    @ApiOperation("删除优惠卷")
//    @PostMapping("/delete")
//    public Map delete(String phone){
//        return null;
//    }
}
